
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author fabian
 */
public class graphsPanel extends JPanel{

        XYSeries series = new XYSeries("X vs t");
        XYSeries series2 = new XYSeries("Y vs t");
        XYSeries series3 = new XYSeries("X vs Y",false);
        final XYSeriesCollection dataset = new XYSeriesCollection(series);
        final XYSeriesCollection dataset2 = new XYSeriesCollection(series2);
        final XYSeriesCollection dataset3 = new XYSeriesCollection(series3);
        final JFreeChart chart = ChartFactory.createXYLineChart(
            "X vs t",
            "tiempo",
            "cord x",
            dataset,
            PlotOrientation.VERTICAL,
            false,
            true,
            false
        );
       final JFreeChart chart2 = ChartFactory.createXYLineChart(
            "Y vs t",
            "tiempo",
            "cord y",
            dataset2,
            PlotOrientation.VERTICAL,
            false,
            true,
            false
        );
      final JFreeChart chart3 = ChartFactory.createXYLineChart(
            "X vs Y",
            "cord X",
            "cord Y",
            dataset3,
            PlotOrientation.VERTICAL,
            false,
            true,
            false
        );
      ChartPanel chartPanel = new ChartPanel(chart);
      ChartPanel chartPanel2 = new ChartPanel(chart2);
      ChartPanel chartPanel3 = new ChartPanel(chart3);
      final XYPlot plot = chart.getXYPlot();
      final XYPlot plot2 = chart2.getXYPlot();
      final XYPlot plot3 = chart3.getXYPlot();
      ValueAxis axis = plot.getDomainAxis();
      ValueAxis axis2 = plot2.getDomainAxis();
      ValueAxis axis3 = plot3.getDomainAxis();
      //chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
      //chartPanel.setSize(200, 100);

public graphsPanel() {

      // end added
      // para hacer una grilla con 3 graficos
        super(new GridBagLayout());

        GridBagConstraints gbc= new GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        this.add(chartPanel, gbc);
        this.add(chartPanel2, gbc);
        this.add(chartPanel3, gbc);
        axis.setAutoRange(true);
        axis2.setAutoRange(true);
        axis3.setAutoRange(true);


    }

public void setData(double Xcord, double Ycord, double time,double ene){
        axis.setFixedAutoRange(ene);  // 60 seconds
        axis2.setFixedAutoRange(ene);  // 60 seconds
       // axis3.setFixedAutoRange(ene);  // 60 seconds
        axis = plot.getRangeAxis();
        axis2 = plot2.getRangeAxis();
        axis3 = plot3.getRangeAxis();
        axis.setRange(-ene/2,ene/2);
        axis2.setRange(-ene/2,ene/2);
        axis3.setRange(-3,5);
        series3.setMaximumItemCount(10000);
    series.add(time,Xcord);
    series2.add(time,Ycord);
    series3.add(Xcord,Ycord);
   // XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
   // renderer.setSeriesLinesVisible(0, true);
   // plot3.setRenderer(renderer);

}
}
